home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / NextAnswers / 1427_C_preprocessor_problem.rtf < prev    next >
Text File  |  1993-11-08  |  2KB  |  49 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f1\fmodern Courier;\f3\fmodern Ohlfs;}
  2. \paperw11760
  3. \paperh7200
  4. \margl120
  5. \margr120
  6. {\colortbl;\red0\green0\blue0;\red81\green81\blue81;\red80\green80\blue80;\red79\green79\blue79;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ulnone\fs28\fc0\cf0 Q:  The following code snippet is excerpted from a Bourne shell script which attempts to determine how to invoke the C preprocessor on any given UNIX platform.  The script creates a file called testcpp.c and runs the C preprocessor on that file redirecting the output to testcpp.out.  When I run this script under NEXTSTEP it incorrectly inserts a space in the output file "
  8. \f1\fs24 abc +xyz
  9. \f0\fs28 ".  This causes the test which confirms "cc -E" as the correct invocation to fail.  Is this a bug in your C preprocessor?\
  10. \
  11.  
  12. \i     \
  13.  
  14. \f1\i0\fs24\fc1\cf1     : see how we invoke the C preprocessor\
  15.     echo " "\
  16.     echo "Checking to see how your C preprocessor is invoked..."\
  17.     cat <<'EOT' >testcpp.c\
  18.     #define ABC abc\
  19.     #define XYZ xyz\
  20.     ABC+XYZ\
  21.     EOT\
  22.     echo 'Maybe "cc -E" will work...'\
  23.     cc -E testcpp.c >testcpp.out 2>&1\
  24.     if $contains 'abc+xyz' testcpp.out >/dev/null 2>&1 ; then\
  25.         echo "Yup, it does."\
  26.         cpp='cc -E'\
  27.     else\
  28.         echo 'Nope...maybe "cc -P" will work...'\
  29.         cc -P testcpp.c >testcpp.out 2>&1\
  30.         if $contains 'abc+xyz' testcpp.out >/dev/null 2>&1 ; then\
  31.         echo "Yup, that does."\
  32.  
  33. \f0\fs28\fc0\cf0 \
  34. A:  The space inserted before the "+xyz" follows the behavior specified by ANSI C.  If you want the old behavior of standard UNIX compilers, use the 
  35. \f1\fs24 -traditional
  36. \f0\fs28  flag.  The man page on cc(1) shows a large number of useful compiler flags in addition to 
  37. \f1\fs24 -traditional
  38. \f0\fs28 .  The flags 
  39. \f1\fs24 -bsd
  40. \f0\fs28  and 
  41. \f1\fs24 -fwritable-strings
  42. \f0\fs28  may also be needed when compiling old UNIX programs.\
  43. \
  44. QA594                \
  45. \
  46. Valid for 2.0, 3.0\
  47. \
  48.  
  49.